﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace SmartSpace
{
    public class Configuration
    {
        private static string _connectionStringName;
        private static bool? _isAutomaticMigrations;

        /// <summary>
        /// 是否自动更新数据库,默认值是true
        /// <para>
        /// AutomaticMigrations=true
        /// </para>
        /// <para>
        /// AutomaticMigrations=false
        /// </para>
        /// </summary>
        public static bool IsAutomaticMigrations
        {
            get
            {
                if (_isAutomaticMigrations == null)
                {
                    if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["AutomaticMigrations"]))
                    {
                        _isAutomaticMigrations = Convert.ToBoolean(ConfigurationManager.AppSettings["AutomaticMigrations"]);
                    }
                    else
                    {
                        _isAutomaticMigrations = true;
                    }
                }
                return _isAutomaticMigrations.Value;
            }
        }

        /// <summary>
        /// 默认连接字符串名称:smartspace
        /// </summary>
        public const string DefaultConnectionStringName = "smartspace";

        /// <summary>
        /// 获取连接字符串
        /// </summary>
        public static string ConnectionStringName
        {
            get
            {
                if (_connectionStringName == null)
                {
                    if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["ConnectionStringName"]))
                    {
                        _connectionStringName = ConfigurationManager.AppSettings["ConnectionStringName"];
                    }
                    else
                    {
                        _connectionStringName = DefaultConnectionStringName;
                    }
                }
                return _connectionStringName;
            }
        }
    }
}
